﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SoftFX.Extended;

namespace Mql2Fdk
{
	internal class BarValues
	{
		#region construction
		public BarValues(Bar[] bars, Func<Bar, double> property)
		{
			m_bars = bars;
			m_property = property;
		}
		#endregion
		#region properties
		public int Count
		{
			get
			{
				return m_bars.Length;
			}
		}
		public double this[int index]
		{
			get
			{
				Bar bar = m_bars[index];
				double result = m_property(bar);
				return result;
			}
		}
		#endregion
		#region property functions
		public static double Open(Bar bar)
		{
			return bar.Open;
		}
		public static double Close(Bar bar)
		{
			return bar.Open;
		}
		public static double Low(Bar bar)
		{
			return bar.Low;
		}
		public static double High(Bar bar)
		{
			return bar.High;
		}
		public static double Volume(Bar bar)
		{
			return bar.Volume;
		}
		public static double Time(Bar bar)
		{
			datetime time = new datetime(bar.From);
			return time.Value;
		}
		#endregion
		#region members
		private readonly Bar[] m_bars;
		private readonly Func<Bar, double> m_property;
		#endregion
	}
}
